package xddq

import (
	"fmt"
	"time"
	D "websocket_apn/define"
	"websocket_apn/log"
	"websocket_apn/proto"
)

// 处理妖盟攻城战所有妖盟排名信息
func (xd *XdDriver) CheckUnionAreaWarInfoData(allInfo []D.UnionAreaWarInfo) {
	fightIdx := -1
	for idx, info := range allInfo {
		if info.LeftCombatValue > 0 && info.ID != xd.UserData.YaoMengID {
			if fightIdx < 0 {
				fightIdx = idx
			}
			log.Infof("妖盟攻城战-%s【%s】第%d名, 城池等级%2d, 剩余妖力%d", info.ID, info.Name, info.Ranking, info.CityLevel, D.GetCombatValueDesc(info.LeftCombatValue))
		}
	}
	if fightIdx >= 0 {
		info := allInfo[fightIdx]
		//log.Infof("妖盟攻城战-开始挑战【%s】 第%d名, 城池等级%2d, 剩余妖力%d", info.Name, info.Ranking, info.CityLevel, info.LeftCombatValue)
		log.Infof("妖盟攻城战-获取妖盟成员信息 %s【%s】 第%d名, 城池等级%2d, 剩余妖力%s", info.ID, info.Name, info.Ranking, info.CityLevel, D.GetCombatValueDesc(info.LeftCombatValue))
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_AREA_WAR_FIGHT_SCENE, fmt.Sprintf("08 %s 10 %s 18 00 20 00", xd.UserData.Activity[D.Activity_UNION_AREA_WAR].ID, info.ID)))
	}
}

// 处理妖盟攻城战-攻击的妖盟信息
func (xd *XdDriver) CheckUnionAreaWarSceneInfoData(info D.UnionAreaWarSceneInfo) {
	if len(info.ID) == 10 && len(info.UseID) == 12 {
		log.Infof("妖盟攻城战-开始攻击妖盟[%s] 成员【%s】", info.ID, info.UseID)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_AREA_WAR_ATTACK, fmt.Sprintf("08 %s 10 %s 18 01 20 %s", xd.UserData.Activity[D.Activity_UNION_AREA_WAR].ID, info.ID, info.UseID)))
		time.Sleep(time.Second)
		xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_AREA_WAR_ATTACK, fmt.Sprintf("08 %s 10 %s 18 %s", xd.UserData.Activity[D.Activity_UNION_AREA_WAR].ID, info.ID, info.UseID)))
		//xd.ResetTaskByID(proto.S_UNION_AREA_WAR_AREA_LIST)
	}
}

// 处理妖盟查看巅峰排行结果
func (xd *XdDriver) CheckUnionHonorHallInfoData(info D.UnionHonorHallInfo) {
	log.Infof("妖盟-巅峰排行赞赏[%s]", info.ID)
	xd.Send(proto.Get_Cmd_Data(xd.userInfo.PlayerId, proto.S_UNION_HONOR_HALL_PEAK_RANK_WORSHIP, fmt.Sprintf("08 %s", info.ID)))
}
